package net.sxjr.protal.zhfx;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import net.sxjr.common.FengKongEnum;
import net.sxjr.common.GlobalParam;
import net.sxjr.common.Response;
import net.sxjr.mbg.entity.IgCadreArchives;
import net.sxjr.mbg.entity.IgRewardsPunishments;
import net.sxjr.mbg.entity.JbdpEmployee;
import net.sxjr.mbg.entity.ZhfxYj;
import net.sxjr.mbg.mapper.IgCadreArchivesMapper;
import net.sxjr.mbg.mapper.IgRewardsPunishmentsMapper;
import net.sxjr.mbg.mapper.JbdpEmployeeMapper;
import net.sxjr.mbg.mapper.ZhfxYjMapper;
import net.sxjr.protal.mapper.ZhfxMapper;
import net.sxjr.protal.publicservice.PublicService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.*;

@Service
public class ZhfxService {
    @Autowired
    private ZhfxMapper zhfxMapper;
    @Autowired
    private ZhfxYjMapper zhfxYjMapper;
    @Autowired
    private IgCadreArchivesMapper cadreArchivesMapper;
    @Autowired
    private IgRewardsPunishmentsMapper rewardsPunishmentsMapper;//党员干部廉政档案
    @Autowired
    private PublicService publicService;
    @Autowired
    private JbdpEmployeeMapper employeeMapper;
    public Response zhleft() {
        Map<String,Object> re = new HashMap<>();
        DecimalFormat df = new DecimalFormat("0.00");
        // 事前提醒预警人数
        Integer currentMonthsqyjrs = zhfxMapper.currentMonthsqyjrs();
        re.put("sqtxrs",currentMonthsqyjrs);
        // 事中监督再提醒人数
        Integer currentMonthszjdrs = zhfxMapper.currentMonthszjdrs();
        re.put("szjdrs",currentMonthszjdrs);
        // 事后评价处置人数
        Integer currentMonthshpjrs = zhfxMapper.currentMonthshpjrs();
        re.put("shpjrs",currentMonthshpjrs);

        List<String> name = new ArrayList<>(4);
        List<Float> value = new ArrayList<>(4);

        //五大监督类型统计
        List<Object> zj = new ArrayList<>(2);
        //合格数
        Integer wdjdhgs = zhfxMapper.wdjdhgs();
        //总数
        Integer wdjdzs = zhfxMapper.wdjdzs();
        JSONObject hege = new JSONObject();
        hege.put("name","合格数占比");
        hege.put("value",change(wdjdhgs,wdjdzs));
        zj.add(hege);
        JSONObject buhege = new JSONObject();
        buhege.put("name","其他占比");
        buhege.put("value",change(wdjdzs-wdjdhgs,wdjdzs));
        zj.add(buhege);
        re.put("bingtu",zj);
        // 三重一大决策合格占比
        //合格数
        Integer szydhgs = zhfxMapper.szydhgs();
        //总数
        Integer szydzs = zhfxMapper.szydzs();
        name.add("三重一大决策合格占比(%)");
        if(szydzs == null || szydzs == 0) {
            value.add((float) 0);
        }else {
            value.add(Float.parseFloat(df.format((float) szydhgs*100 / szydzs)));
        }
        // 干部管理监督合格占比
        //合格数
        Integer gbjdglhgs = zhfxMapper.gbjdglhgs();
        //总数
        Integer gbjdglzs = zhfxMapper.gbjdglzs();
        name.add("干部管理监督合格占比(%)");
        if(gbjdglzs == null || gbjdglzs == 0) {
            value.add((float) 0);
        }else {
            value.add(Float.parseFloat(df.format((float) gbjdglhgs*100 / gbjdglzs)));
        }
        // 薪酬管理监督合格占比

        //合格数
        Integer xcgljdhgs = zhfxMapper.xcgljdhgs();
        //总数
        Integer xcgljdzs = zhfxMapper.xcgljdzs();
        name.add("薪酬管理监督合格占比(%)");
        if(xcgljdzs == null || xcgljdzs == 0) {
            value.add((float) 0);
        }else {
            value.add(Float.parseFloat(df.format((float) xcgljdhgs*100 / xcgljdzs)));
        }
        //项目管理监督合格占比
        //合格数
        Integer xmjdhgs = zhfxMapper.xmjdhgs();
        //总数
        Integer xmjdzs = zhfxMapper.xmjdzs();
        name.add("项目管理监督合格占比(%)");
        if(xmjdzs == null || xmjdzs == 0) {
            value.add((float) 0);
        }else {
            value.add(Float.parseFloat(df.format((float) xmjdhgs*100 / xmjdzs)));
        }

        re.put("zznameData",name);
        re.put("zzvalueData",value);


        //预警人次趋势
        Calendar c = Calendar.getInstance();
        int year = c.get(Calendar.YEAR);
        List<ZhfxYj> zhfxYjs = zhfxYjMapper.selectList(new LambdaQueryWrapper<ZhfxYj>().gt(ZhfxYj::getMonth, year+""));

        List<Object> zhixianList = new ArrayList<>();
        JSONObject sq = new JSONObject();
        JSONObject sz = new JSONObject();
        JSONObject sh = new JSONObject();

        List<Integer> sqList = new ArrayList<>();
        List<Integer> szList = new ArrayList<>();
        List<Integer> shList = new ArrayList<>();
        for (String month : GlobalParam.month) {
            String time =  year+"-"+month;
            Optional<ZhfxYj> first = zhfxYjs.stream().filter(v -> time.equals(v.getMonth())).findFirst();
            if(!first.isPresent()){
                sqList.add(0);
                szList.add(0);
                shList.add(0);
                continue;
            }
            ZhfxYj zhfxYj = first.get();
            sqList.add(zhfxYj.getYujingSq());
            szList.add(zhfxYj.getYujingSz());
            shList.add(zhfxYj.getYujingSh());

        }

        sq.put("name","事前提醒预警人数");
        sq.put("type","line");
        sq.put("smooth",true);
        sq.put("data",sqList);
        zhixianList.add(sq);

        sz.put("name","事中监督再提醒人数");
        sz.put("type","line");
        sz.put("smooth",true);
        sz.put("data",szList);
        zhixianList.add(sz);

        sh.put("name","事后评价处置人数");
        sh.put("type","line");
        sh.put("smooth",true);
        sh.put("data",shList);
        zhixianList.add(sh);

        re.put("zhixianData",zhixianList);


        return Response.success(re);


    }

    public Response zhmiddle(){
        JSONObject re = new JSONObject();
        //档案总人数
        Integer count = cadreArchivesMapper.selectCount(new LambdaQueryWrapper<>());
        re.put("dazrs",String.format("%04d", count));
        //新增人数
        Calendar c = Calendar.getInstance();
        c.set(Calendar.DAY_OF_YEAR,1);
        Integer xzrs = cadreArchivesMapper.selectCount(new LambdaQueryWrapper<IgCadreArchives>().gt(IgCadreArchives::getDateOfFilling, c.getTime()));
        re.put("xzrs",String.format("%04d", xzrs));
        //有处罚人数
        Integer ycfrs = zhfxMapper.ycfrs();
        re.put("ycfrs",String.format("%04d", ycfrs));
        //无处罚人数
        Integer fycfrs = zhfxMapper.fycfrs();
        re.put("fycfrs",String.format("%04d", fycfrs));

        JSONArray arr = new JSONArray();
        //处罚通报
        List<IgRewardsPunishments> punishments = rewardsPunishmentsMapper.selectList(new LambdaQueryWrapper<IgRewardsPunishments>().gt(IgRewardsPunishments::getCreateDate, Calendar.getInstance().get(Calendar.YEAR) + ""));
        try {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            for (IgRewardsPunishments punishment : punishments) {
                FengKongEnum project = publicService.getProject(punishment.getProjectId());
                if(project == null) continue;
                JbdpEmployee employee = employeeMapper.selectById(punishment.getEmpId());
                JSONObject cftb = new JSONObject();
                cftb.put("name",employee.getEmployeeName());
                cftb.put("scjdlx",project.getJianduType());
                cftb.put("fklx",project.getFengkongType());
                cftb.put("cfsj",sdf.format(punishment.getRpDate()));

                arr.add(cftb);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        re.put("cftbList",arr);
        return Response.success(re);
    }

    public Response zhright(){
        JSONObject re = new JSONObject();

        //评价
        Calendar c = Calendar.getInstance();
        int year = c.get(Calendar.YEAR);
        List<ZhfxYj> zhfx = zhfxYjMapper.selectList(new LambdaQueryWrapper<ZhfxYj>().gt(ZhfxYj::getMonth, year+""));

        List<Object> zhuzhuangList = new ArrayList<>();
        JSONObject hege = new JSONObject();
        JSONObject buhege = new JSONObject();

        List<Integer> hegeList = new ArrayList<>();
        List<Integer> buhegeList = new ArrayList<>();
        for (String month : GlobalParam.month) {
            String time =  year+"-"+month;
            Optional<ZhfxYj> first = zhfx.stream().filter(v -> time.equals(v.getMonth())).findFirst();
            if(!first.isPresent()){
                hegeList.add(0);
                buhegeList.add(0);
                continue;
            }
            ZhfxYj zhfxYj = first.get();
            hegeList.add(zhfxYj.getPingjiaHege());
            buhegeList.add(zhfxYj.getPingjiaBuhege());
        }
        hege.put("name","合格");
        hege.put("type","bar");
        hege.put("stack","评价人数");
        hege.put("data",hegeList);
        JSONObject itemStyle = new JSONObject();
        JSONObject normal =  new JSONObject();
        normal.put("color","#40b8d1");
        itemStyle.put("normal",normal);
        hege.put("itemStyle",itemStyle);

        buhege.put("name","不合格");
        buhege.put("type","bar");
        buhege.put("stack","评价人数");
        buhege.put("data",hegeList);
        JSONObject itemStyle1 = new JSONObject();
        JSONObject normal1 =  new JSONObject();
        normal1.put("color","#f29961");
        itemStyle1.put("normal",normal1);
        buhege.put("itemStyle",itemStyle1);

        zhuzhuangList.add(hege);
        zhuzhuangList.add(buhege);

        JSONArray bingtu = new JSONArray();
        //结果应用

        //有处罚人数
        Integer ycfrs = zhfxMapper.ycfrs();
        //无处罚人数
        Integer fycfrs = zhfxMapper.fycfrs();
        JSONObject chufa = new JSONObject();
        chufa.put("name","处罚");
        chufa.put("value",ycfrs+fycfrs);
        bingtu.add(chufa);

        //评价（记录数）  4大类项目的 风险评价字段 非空
        Integer pingjiaCount = zhfxMapper.pingjiaCount();
        JSONObject pingjia = new JSONObject();
        pingjia.put("name","评价");
        pingjia.put("value",pingjiaCount);
        bingtu.add(pingjia);
        // 处置监察（记录数）
        Integer chuzhijianchaCount = zhfxMapper.chuzhijianchaCount();
        JSONObject chuzhijiancha = new JSONObject();
        chuzhijiancha.put("name","处置监察");
        chuzhijiancha.put("value",chuzhijianchaCount);
        bingtu.add(chuzhijiancha);
        //结果应用（记录数）
        Integer jieguoyingyongCount = zhfxMapper.jieguoyingyongCount();
        JSONObject jieguoyingyong = new JSONObject();
        jieguoyingyong.put("name","结果应用");
        jieguoyingyong.put("value",jieguoyingyongCount);
        bingtu.add(jieguoyingyong);


        re.put("zhuzhuangList",zhuzhuangList);
        re.put("bingtuData",bingtu);
        return Response.success(re);
    }

    // type  1 三重一大 2 项目监督 3 薪酬监督 4 干部监督
    public Response mokuaiLeft(Integer type){
        JSONObject re =  new JSONObject();
        int currentMonthHgs = 0;
        int shangMonthHgs = 0;
        int qunianHgs = 0;


        int currentMonthbHgs = 0;
        int shangMonthbHgs = 0;
        int qunianbHgs = 0;

        //不合格项目
        List buhegeList = null;

        //查询上月数据
        Calendar c = Calendar.getInstance();
        c.set(Calendar.MONTH,-1);
        int year = c.get(Calendar.YEAR);
        int month = c.get(Calendar.MONTH);
        ZhfxYj shangyeData = zhfxYjMapper.selectOne(new LambdaQueryWrapper<ZhfxYj>().eq(ZhfxYj::getMonth, year + "-" + month));

        c= Calendar.getInstance();
        c.set(Calendar.YEAR,-1);
        year = c.get(Calendar.YEAR);
        month = c.get(Calendar.MONTH);
        ZhfxYj quNianData = zhfxYjMapper.selectOne(new LambdaQueryWrapper<ZhfxYj>().eq(ZhfxYj::getMonth, year + "-" + month));

        //一年内评价结果为合格与不合格
        List<ZhfxYj> zhfxYjs = zhfxYjMapper.selectList(new LambdaQueryWrapper<ZhfxYj>().gt(ZhfxYj::getMonth, Calendar.getInstance().get(Calendar.YEAR) + ""));

        List<Integer> hegetubiaoList = new ArrayList<>(12);
        List<Integer> buhegetubiaoList = new ArrayList<>(12);
        // type  1 三重一大 2 项目监督 3 薪酬监督 4 干部监督
        if(type == 1){
            //本月合格次数 上月合格次数  同比上升
            currentMonthHgs = zhfxMapper.szydhgs();
            if(shangyeData != null) {
                shangMonthHgs = shangyeData.getPingjiaHegeSzyd();
            }
            if(quNianData != null){
                qunianHgs = quNianData.getPingjiaHegeSzyd();
            }


            currentMonthbHgs = zhfxMapper.szydzs()-currentMonthHgs;
            if(shangyeData != null) {
                shangMonthbHgs = shangyeData.getPingjiaBuhegeSzyd();
            }
            if(quNianData != null){
                qunianbHgs = quNianData.getPingjiaBuhegeSzyd();
            }

            for (String m : GlobalParam.month) {
                String time =  year+"-"+m;
                Optional<ZhfxYj> first = zhfxYjs.stream().filter(v -> time.equals(v.getMonth())).findFirst();
                if(!first.isPresent()){
                    hegetubiaoList.add(0);
                    buhegetubiaoList.add(0);
                    continue;
                }
                ZhfxYj zhfxYj = first.get();
                hegetubiaoList.add(zhfxYj.getPingjiaHegeSzyd());
                buhegetubiaoList.add(zhfxYj.getPingjiaBuhegeSzyd());
            }

            buhegeList = zhfxMapper.szydBuhegeList();


        }else if (type == 2){
            currentMonthHgs = zhfxMapper.xmjdhgs();
            if(shangyeData != null) {
                shangMonthHgs = shangyeData.getPingjiaHegeXmgl();
            }
            if(quNianData != null){
                qunianHgs = quNianData.getPingjiaHegeGbgl();
            }


            currentMonthbHgs = zhfxMapper.xmjdzs()-currentMonthHgs;
            if(shangyeData != null) {
                shangMonthbHgs = shangyeData.getPingjiaBuhegeXmgl();
            }
            if(quNianData != null){
                qunianbHgs = quNianData.getPingjiaBuhegeXmgl();
            }

            for (String m : GlobalParam.month) {
                String time =  year+"-"+m;
                Optional<ZhfxYj> first = zhfxYjs.stream().filter(v -> time.equals(v.getMonth())).findFirst();
                if(!first.isPresent()){
                    hegetubiaoList.add(0);
                    buhegetubiaoList.add(0);
                    continue;
                }
                ZhfxYj zhfxYj = first.get();
                hegetubiaoList.add(zhfxYj.getPingjiaHegeXmgl());
                buhegetubiaoList.add(zhfxYj.getPingjiaBuhegeXmgl());
            }

            buhegeList = zhfxMapper.xmjdBuhegeList();

        }else if (type == 3){
            currentMonthHgs = zhfxMapper.xcgljdhgs();
            if(shangyeData != null) {
                shangMonthHgs = shangyeData.getPingjiaHegeXcgl();
            }
            if(quNianData != null){
                qunianHgs = quNianData.getPingjiaHegeGbgl();
            }

            currentMonthbHgs = zhfxMapper.xcgljdzs()-currentMonthHgs;
            if(shangyeData != null) {
                shangMonthbHgs = shangyeData.getPingjiaBuhegeXcgl();
            }
            if(quNianData != null){
                qunianbHgs = quNianData.getPingjiaBuhegeXcgl();
            }

            for (String m : GlobalParam.month) {
                String time =  year+"-"+m;
                Optional<ZhfxYj> first = zhfxYjs.stream().filter(v -> time.equals(v.getMonth())).findFirst();
                if(!first.isPresent()){
                    hegetubiaoList.add(0);
                    buhegetubiaoList.add(0);
                    continue;
                }
                ZhfxYj zhfxYj = first.get();
                hegetubiaoList.add(zhfxYj.getPingjiaHegeXcgl());
                buhegetubiaoList.add(zhfxYj.getPingjiaBuhegeXcgl());
            }

            buhegeList = zhfxMapper.xcjdBuhegeList();

        }else if (type == 4){
            currentMonthHgs = zhfxMapper.gbjdglhgs();
            if(shangyeData != null) {
                shangMonthHgs = shangyeData.getPingjiaHegeGbgl();
            }
            if(quNianData != null){
                qunianHgs = quNianData.getPingjiaHegeGbgl();
            }

            currentMonthbHgs = zhfxMapper.gbjdglzs()-currentMonthHgs;
            if(shangyeData != null) {
                shangMonthbHgs = shangyeData.getPingjiaBuhegeGbgl();
            }
            if(quNianData != null){
                qunianbHgs = quNianData.getPingjiaBuhegeGbgl();
            }

            for (String m : GlobalParam.month) {
                String time =  year+"-"+m;
                Optional<ZhfxYj> first = zhfxYjs.stream().filter(v -> time.equals(v.getMonth())).findFirst();
                if(!first.isPresent()){
                    hegetubiaoList.add(0);
                    buhegetubiaoList.add(0);
                    continue;
                }
                ZhfxYj zhfxYj = first.get();
                hegetubiaoList.add(zhfxYj.getPingjiaHegeGbgl());
                buhegetubiaoList.add(zhfxYj.getPingjiaBuhegeGbgl());
            }

            buhegeList = zhfxMapper.gbglBUhegeList();

        }

        re.put("currentMonthHgs",currentMonthHgs);
        re.put("shangMonthHgs",shangMonthHgs);
        re.put("qunianHgs",qunianHgs);

        re.put("currentMonthbHgs",currentMonthbHgs);
        re.put("shangMonthbHgs",shangMonthbHgs);
        re.put("qunianbHgs",qunianbHgs);


        re.put("buhegeList", buhegeList);


        JSONObject jianduqushifenxihege = new JSONObject();
        jianduqushifenxihege.put("name","合格监督");
        jianduqushifenxihege.put("data",hegetubiaoList);
        re.put("jianduqushifenxihege",jianduqushifenxihege);

        JSONObject jianduqushifenxibuhege = new JSONObject();
        jianduqushifenxibuhege.put("name","不合格监督");
        jianduqushifenxibuhege.put("data",buhegetubiaoList);
        re.put("jianduqushifenxibuhege",jianduqushifenxibuhege);


        return Response.success(re);
    }

    // type  1 三重一大 2 项目监督 3 薪酬监督 4 干部监督
    public Response mokuaiMiddle(Integer type){
        JSONObject re = new JSONObject();

        int year = Calendar.getInstance().get(Calendar.YEAR);
        //一年内评价结果为合格与不合格
        List<ZhfxYj> zhfxYjs = zhfxYjMapper.selectList(new LambdaQueryWrapper<ZhfxYj>().gt(ZhfxYj::getMonth,  year+ ""));

        List<Object> zhuzhuangtuData = new ArrayList<>();
        String[] s = {"product","事前提醒预警","事中跟踪监督","事后评价处置"};
        zhuzhuangtuData.add(s);

        if(type == 1){
            for (String m : GlobalParam.month) {
                String time =  year+"-"+m;
                List<Object> monthData = new ArrayList<>();
                monthData.add(m+"月");

                Optional<ZhfxYj> first = zhfxYjs.stream().filter(v -> time.equals(v.getMonth())).findFirst();
                if(!first.isPresent()){
                    monthData.add(0);
                    monthData.add(0);
                    monthData.add(0);
                    zhuzhuangtuData.add(monthData);
                    continue;
                }
                ZhfxYj zhfxYj = first.get();
                monthData.add(zhfxYj.getYujingSqSzyd());
                monthData.add(zhfxYj.getYujingSzSzyd());
                monthData.add(zhfxYj.getYujingShSzyd());
                zhuzhuangtuData.add(monthData);
            }

        }else if(type == 2){
            for (String m : GlobalParam.month) {
                String time =  year+"-"+m;
                List<Object> monthData = new ArrayList<>();
                monthData.add(m+"月");

                Optional<ZhfxYj> first = zhfxYjs.stream().filter(v -> time.equals(v.getMonth())).findFirst();
                if(!first.isPresent()){
                    monthData.add(0);
                    monthData.add(0);
                    monthData.add(0);
                    zhuzhuangtuData.add(monthData);
                    continue;
                }
                ZhfxYj zhfxYj = first.get();
                monthData.add(zhfxYj.getYujingSqXmgl());
                monthData.add(zhfxYj.getYujingSzXmgl());
                monthData.add(zhfxYj.getYujingShXmgl());
                zhuzhuangtuData.add(monthData);
            }

        }else if(type == 3){
            for (String m : GlobalParam.month) {
                String time =  year+"-"+m;
                List<Object> monthData = new ArrayList<>();
                monthData.add(m+"月");

                Optional<ZhfxYj> first = zhfxYjs.stream().filter(v -> time.equals(v.getMonth())).findFirst();
                if(!first.isPresent()){
                    monthData.add(0);
                    monthData.add(0);
                    monthData.add(0);
                    zhuzhuangtuData.add(monthData);
                    continue;
                }
                ZhfxYj zhfxYj = first.get();
                monthData.add(zhfxYj.getYujingSqXcgl());
                monthData.add(zhfxYj.getYujingSzXcgl());
                monthData.add(zhfxYj.getYujingShXcgl());
                zhuzhuangtuData.add(monthData);
            }
        }else if(type == 4){
            for (String m : GlobalParam.month) {
                String time =  year+"-"+m;
                List<Object> monthData = new ArrayList<>();
                monthData.add(m+"月");

                Optional<ZhfxYj> first = zhfxYjs.stream().filter(v -> time.equals(v.getMonth())).findFirst();
                if(!first.isPresent()){
                    monthData.add(0);
                    monthData.add(0);
                    monthData.add(0);
                    zhuzhuangtuData.add(monthData);
                    continue;
                }
                ZhfxYj zhfxYj = first.get();
                monthData.add(zhfxYj.getYujingSqGbgl());
                monthData.add(zhfxYj.getYujingSzGbgl());
                monthData.add(zhfxYj.getYujingShGbgl());
                zhuzhuangtuData.add(monthData);
            }
        }
        //风控数量
        int fengkongCount ;//项目总数量
        Integer szydzs = zhfxMapper.szydzs();// 三重一大
        Integer xmjdzs = zhfxMapper.xmjdzs();//项目管理
        Integer xcgljdzs = zhfxMapper.xcgljdzs();// 薪酬管理
        Integer gbjdglzs = zhfxMapper.gbjdglzs();// 干部管理

        fengkongCount = szydzs+xmjdzs+xcgljdzs+gbjdglzs;
        re.put("fengkongCount",fengkongCount);
        re.put("szydzs",szydzs);
        re.put("xmjdzs",xmjdzs);
        re.put("xcgljdzs",xcgljdzs);
        re.put("gbjdglzs",gbjdglzs);
        re.put("zhuzhuangtuData",zhuzhuangtuData);
        return Response.success(re);

    }

    // type  1 三重一大 2 项目监督 3 薪酬监督 4 干部监督
    public Response mokuaiRight(Integer type){
        JSONObject re = new JSONObject();

        //一年内结果
        int year = Calendar.getInstance().get(Calendar.YEAR);
        List<ZhfxYj> zhfxYjs = zhfxYjMapper.selectList(new LambdaQueryWrapper<ZhfxYj>().gt(ZhfxYj::getMonth,  year+ ""));

        JSONArray zhexiantu = new JSONArray(3);
        JSONObject sq = new JSONObject();
        sq.put("name","事前");
        sq.put("type","line");
        sq.put("stack","总量");
        sq.put("smooth",true);
        sq.put("symbol","none");
        JSONObject aa = new JSONObject();
        aa.put("width",3);
        sq.put("lineStyle",aa);
        JSONObject sz = new JSONObject();
        sz.put("name","事中");
        sz.put("type","line");
        sz.put("stack","总量");
        sz.put("smooth",true);
        sz.put("symbol","none");
        sz.put("lineStyle",aa);
        JSONObject sh = new JSONObject();
        sh.put("name","事后");
        sh.put("type","line");
        sh.put("stack","总量");
        sh.put("smooth",true);
        sh.put("symbol","none");
        sh.put("lineStyle",aa);

        JSONArray sqdata = new JSONArray(12);
        JSONArray szdata = new JSONArray(12);
        JSONArray shdata = new JSONArray(12);

        JSONArray jieguoyingyongArr = new JSONArray();
        JSONArray fengkongleibieArr = new JSONArray();

        int fengkongshuliang = 0;
        int fengkongshuliang_old = 0;
        int fengkonghege = 0;
        int fengkongbuhege = 0;

        int chengjiajine = 0;
        int chengjiajine_old = 0;

        //去年当月
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
        Calendar cc = Calendar.getInstance();
        cc.set(Calendar.YEAR,-1);
        String s = sdf.format(cc.getTime());
        ZhfxYj qunian = zhfxYjMapper.selectOne(new LambdaQueryWrapper<ZhfxYj>().eq(ZhfxYj::getMonth, s));

        if(type == 1){
            Integer dezj = zhfxMapper.jieguoyingyongszyd_dezj();
            Integer zdjc = zhfxMapper.jieguoyingyongszyd_zdjc();
            Integer zdrs = zhfxMapper.jieguoyingyongszyd_zdrs();
            Integer zdxm = zhfxMapper.jieguoyingyongszyd_zdxm();
            JSONObject dezi_j = new JSONObject();
            dezi_j.put("name","大额资金");
            dezi_j.put("value",dezj);
            jieguoyingyongArr.add(dezi_j);

            JSONObject zdjc_j = new JSONObject();
            zdjc_j.put("name","重大决策");
            zdjc_j.put("value",zdjc);
            jieguoyingyongArr.add(zdjc_j);

            JSONObject zdrs_j = new JSONObject();
            zdrs_j.put("name","重大人事");
            zdrs_j.put("value",zdrs);
            jieguoyingyongArr.add(zdrs_j);

            JSONObject zdxm_j = new JSONObject();
            zdxm_j.put("name","重大项目");
            zdxm_j.put("value",zdxm);
            jieguoyingyongArr.add(zdxm_j);


            Integer pingjiadezj = zhfxMapper.pingjiaszyd_dezj();
            Integer pingjiazdjc = zhfxMapper.pingjiaszyd_zdjc();
            Integer pingjiazdrs = zhfxMapper.pingjiaszyd_zdrs();
            Integer pingjiazdxm = zhfxMapper.pingjiaszyd_zdxm();
            JSONObject pingjiadezi_j = new JSONObject();
            pingjiadezi_j.put("name","大额资金");
            pingjiadezi_j.put("value",pingjiadezj);
            fengkongleibieArr.add(pingjiadezi_j);

            JSONObject pingjiazdjc_j = new JSONObject();
            pingjiazdjc_j.put("name","重大决策");
            pingjiazdjc_j.put("value",pingjiazdjc);
            fengkongleibieArr.add(pingjiazdjc_j);

            JSONObject pingjiazdrs_j = new JSONObject();
            pingjiazdrs_j.put("name","重大人事");
            pingjiazdrs_j.put("value",pingjiazdrs);
            fengkongleibieArr.add(pingjiazdrs_j);

            JSONObject pingjiazdxm_j = new JSONObject();
            pingjiazdxm_j.put("name","重大项目");
            pingjiazdxm_j.put("value",pingjiazdxm);
            fengkongleibieArr.add(pingjiazdxm_j);

            //项目数量
            fengkonghege = zhfxMapper.szydhgs();
            fengkongshuliang = zhfxMapper.szydzs();
            if(qunian != null) {
                Integer pingjiaBuhegeSzyd = qunian.getPingjiaBuhegeSzyd();
                Integer pingjiaHegeSzyd = qunian.getPingjiaHegeSzyd();
                if(pingjiaBuhegeSzyd != null && pingjiaHegeSzyd != null) {
                    fengkongshuliang_old = pingjiaBuhegeSzyd + pingjiaHegeSzyd;
                    fengkongbuhege = fengkongshuliang - fengkonghege;
                }
            }


            for (String m : GlobalParam.month) {
                String time =  year+"-"+m;
                Optional<ZhfxYj> first = zhfxYjs.stream().filter(v -> time.equals(v.getMonth())).findFirst();
                if(!first.isPresent()){
                    sqdata.add(0);
                    szdata.add(0);
                    shdata.add(0);
                    continue;
                }
                ZhfxYj zhfxYj = first.get();
                sqdata.add(zhfxYj.getYujingSqSzyd());
                szdata.add(zhfxYj.getYujingSzSzyd());
                shdata.add(zhfxYj.getYujingShSzyd());
            }
        }else if(type ==2){
            Integer cg = zhfxMapper.jieguoyingyongxmgl_cg();
            Integer fw = zhfxMapper.jieguoyingyongxmgl_fw();
            Integer js = zhfxMapper.jieguoyingyongxmgl_js();
            JSONObject cg_j = new JSONObject();
            cg_j.put("name","采购类");
            cg_j.put("value",cg);
            jieguoyingyongArr.add(cg_j);

            JSONObject fw_j = new JSONObject();
            fw_j.put("name","服务类");
            fw_j.put("value",fw);
            jieguoyingyongArr.add(fw_j);

            JSONObject js_j = new JSONObject();
            js_j.put("name","建设类");
            js_j.put("value",js);
            jieguoyingyongArr.add(js_j);


            Integer pingjiacg = zhfxMapper.pingjiaxmgl_cg();
            Integer pingjiafw = zhfxMapper.pingjiaxmgl_fw();
            Integer pingjiajs = zhfxMapper.pingjiaxmgl_js();
            JSONObject pingjiacg_j = new JSONObject();
            pingjiacg_j.put("name","采购类");
            pingjiacg_j.put("value",pingjiacg);
            fengkongleibieArr.add(pingjiacg_j);

            JSONObject pingjiafw_j = new JSONObject();
            pingjiafw_j.put("name","建设类");
            pingjiafw_j.put("value",pingjiafw);
            fengkongleibieArr.add(pingjiafw_j);

            JSONObject pingjiajs_j = new JSONObject();
            pingjiajs_j.put("name","服务类");
            pingjiajs_j.put("value",pingjiajs);
            fengkongleibieArr.add(pingjiajs_j);


            //项目数量
            fengkonghege = zhfxMapper.xmjdhgs();
            fengkongshuliang = zhfxMapper.xmjdzs();
            if(qunian != null) {
                Integer pingjiaBuhegeSzyd = qunian.getPingjiaBuhegeXmgl();
                Integer pingjiaHegeSzyd = qunian.getPingjiaHegeXmgl();
                if (pingjiaBuhegeSzyd != null && pingjiaHegeSzyd != null) {
                    fengkongshuliang_old = pingjiaBuhegeSzyd + pingjiaHegeSzyd;
                    fengkongbuhege = fengkongshuliang - fengkonghege;
                }
            }
            Integer xmglxiangmujiee = zhfxMapper.xmglxiangmujiee();
            chengjiajine = xmglxiangmujiee== null?0:xmglxiangmujiee;
            if(qunian != null) {
                chengjiajine_old = qunian.getXmglxmje();
            }
            for (String m : GlobalParam.month) {
                String time =  year+"-"+m;
                Optional<ZhfxYj> first = zhfxYjs.stream().filter(v -> time.equals(v.getMonth())).findFirst();
                if(!first.isPresent()){
                    sqdata.add(0);
                    szdata.add(0);
                    shdata.add(0);
                    continue;
                }
                ZhfxYj zhfxYj = first.get();
                sqdata.add(zhfxYj.getYujingSqXmgl());
                szdata.add(zhfxYj.getYujingSzXmgl());
                shdata.add(zhfxYj.getYujingShXmgl());
            }
        }else if(type ==3){
            Integer tb = zhfxMapper.jieguoyingyongxcgl();
            JSONObject tb_j = new JSONObject();
            tb_j.put("name","薪酬管理");
            tb_j.put("value",tb);
            jieguoyingyongArr.add(tb_j);

            Integer xcgljdzs = zhfxMapper.xcgljdzs();

            JSONObject xcgljdzs_j = new JSONObject();
            xcgljdzs_j.put("name","薪酬管理");
            xcgljdzs_j.put("value",xcgljdzs);
            fengkongleibieArr.add(xcgljdzs_j);

            //项目数量
            fengkonghege = zhfxMapper.xcgljdhgs();
            fengkongshuliang = zhfxMapper.xcgljdzs();
            if(qunian != null) {
                Integer pingjiaBuhegeSzyd = qunian.getPingjiaBuhegeXcgl();
                Integer pingjiaHegeSzyd = qunian.getPingjiaHegeXcgl();
                if (pingjiaBuhegeSzyd != null && pingjiaHegeSzyd != null) {
                    fengkongshuliang_old = pingjiaBuhegeSzyd + pingjiaHegeSzyd;
                    fengkongbuhege = fengkongshuliang - fengkonghege;
                }
            }
            for (String m : GlobalParam.month) {
                String time =  year+"-"+m;
                Optional<ZhfxYj> first = zhfxYjs.stream().filter(v -> time.equals(v.getMonth())).findFirst();
                if(!first.isPresent()){
                    sqdata.add(0);
                    szdata.add(0);
                    shdata.add(0);
                    continue;
                }
                ZhfxYj zhfxYj = first.get();
                sqdata.add(zhfxYj.getYujingSqXcgl());
                szdata.add(zhfxYj.getYujingSzXcgl());
                shdata.add(zhfxYj.getYujingShXcgl());
            }
        }else if(type ==4){
            Integer tb = zhfxMapper.jieguoyingyonggbgl_tb();
            Integer zd = zhfxMapper.jieguoyingyonggbgl_zd();
            JSONObject tb_j = new JSONObject();
            tb_j.put("name","干部提拔");
            tb_j.put("value",tb);
            jieguoyingyongArr.add(tb_j);

            JSONObject zd_j = new JSONObject();
            zd_j.put("name","干部走动");
            zd_j.put("value",zd);
            jieguoyingyongArr.add(zd_j);

            Integer pingjiatb = zhfxMapper.pingjiagbgl_tb();
            Integer pingjiazd = zhfxMapper.pingjiagbgl_zd();
            JSONObject pingjiatb_j = new JSONObject();
            pingjiatb_j.put("name","干部提拔");
            pingjiatb_j.put("value",pingjiatb);
            fengkongleibieArr.add(pingjiatb_j);

            JSONObject pingjiazd_j = new JSONObject();
            pingjiazd_j.put("name","干部走动");
            pingjiazd_j.put("value",pingjiazd);
            fengkongleibieArr.add(pingjiazd_j);


            //项目数量
            fengkonghege = zhfxMapper.gbjdglhgs();
            fengkongshuliang = zhfxMapper.gbjdglzs();
            if(qunian != null) {
                Integer pingjiaBuhegeSzyd = qunian.getPingjiaBuhegeGbgl();
                Integer pingjiaHegeSzyd = qunian.getPingjiaHegeGbgl();
                if (pingjiaBuhegeSzyd != null && pingjiaHegeSzyd != null) {
                    fengkongshuliang_old = pingjiaBuhegeSzyd + pingjiaHegeSzyd;
                    fengkongbuhege = fengkongshuliang - fengkonghege;
                }
            }

            for (String m : GlobalParam.month) {
                String time =  year+"-"+m;
                Optional<ZhfxYj> first = zhfxYjs.stream().filter(v -> time.equals(v.getMonth())).findFirst();
                if(!first.isPresent()){
                    sqdata.add(0);
                    szdata.add(0);
                    shdata.add(0);
                    continue;
                }
                ZhfxYj zhfxYj = first.get();
                sqdata.add(zhfxYj.getYujingSqGbgl());
                szdata.add(zhfxYj.getYujingSzGbgl());
                shdata.add(zhfxYj.getYujingShGbgl());
            }
        }

        sq.put("data",sqdata);
        sz.put("data",szdata);
        sh.put("data",shdata);

        zhexiantu.add(sq);
        zhexiantu.add(sz);
        zhexiantu.add(sh);
        re.put("jieguoyingyong",jieguoyingyongArr);
        re.put("fengkongleibie",fengkongleibieArr);
        re.put("zhexiantu",zhexiantu);
        re.put("fengkonghege",fengkonghege);
        re.put("fengkongshuliang",fengkongshuliang);
        re.put("fengkongshuliang_old",fengkongshuliang_old);
        re.put("fengkongbuhege",fengkongbuhege);

        re.put("chengjiajine",chengjiajine);
        re.put("chengjiajine_old",chengjiajine_old);
        return Response.success(re);
    }



    private Float change(Integer a,Integer b){

        DecimalFormat df = new DecimalFormat("0.00");
        if(a == null || a == 0 || b == null || b == 0){
            return Float.parseFloat(df.format((float)0));
        }
        return Float.parseFloat(df.format((float) a*100 / b));
    }


}
